package com.reservationserver.controller.user;

import com.reservationpojo.domin.vo.Adduservo;
import com.reservationpojo.domin.vo.Userlogvo;
import com.reservationpojo.entity.User;
import com.reservationpojo.utils.Result;
import com.reservationserver.mapper.user.Usermapper;
import com.reservationserver.service.admin.Textservice;
import com.reservationserver.service.user.Userservice;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/userlogin")
@Tag(name = "用户登录")
public class Userlogincontroller {
    private final Userservice userservice;
    private final Usermapper usermapper;
    private  final Textservice textservice;
    /**
     *
     * @param uservo
     * @return
     */
    @Operation(summary = "第一次登录")
    @PostMapping("/add")
    public Result adduser(@RequestBody Adduservo uservo){
        log.info("按照id或empname查询:{}", uservo);
        userservice.adduser(uservo);
        return Result.success();
    }

    /**
     *
     * @param userlog
     * @return
     */
    @Operation(summary = "登录")
    @GetMapping("/login")
    public Result mgrlogin(@RequestBody Userlogvo userlog){
        User user=usermapper.userlog(userlog.getWxId());
        if(user!=null){
            log.info("##########{}",user);
            return Result.success(user);
        }
return Result.error("未登录");
    }

    /**
     *
     * @param classA
     * @return
     */
    @Operation(summary = "用户查看公告")
    @GetMapping("/gettext")
    public Result gettext(String classA){
        String text_content=textservice.gettest(classA);
        return Result.success(text_content);
    }
}
